package com.chenss.dragonserapp.adapter;

import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.chenss.dragonserapp.R;
import com.chenss.dragonserapp.base.BaseAdp;
import com.chenss.dragonserapp.model.OrderListModel;
import com.chenss.dragonserapp.model.OrderRetrunListModel;

import java.util.List;

public class OrderReturnListAdapter extends BaseAdp<OrderRetrunListModel> {

	public OrderReturnListAdapter(Context ctx, List<OrderRetrunListModel> list) {
		super(ctx, list, R.layout.item_frag_order);
	}

	@Override
	public void Convert(final int position, View convertView) {
		// TODO Auto-generated method stub
//		退货状态【1:待审核】【2:待退货】【3:待换货】【4:已完成】【5审核未通过】
		LinearLayout ll_state = Get(convertView,R.id.ll_state);
		LinearLayout ll_goods = Get(convertView,R.id.ll_goods);
		TextView tv_state = Get(convertView,R.id.tv_state);
		TextView tv_orderNo = Get(convertView,R.id.tv_orderNo);
		TextView tv_addr = Get(convertView,R.id.tv_addr);
		TextView tv_time = Get(convertView,R.id.tv_time);
		TextView tv_all_price = Get(convertView,R.id.tv_allPrice);
		TextView tv_total = Get(convertView,R.id.tv_total);

		tv_orderNo.setText(mDataList.get(position).getReturn_number());
		tv_addr.setText(mDataList.get(position).getReturn_receiver_address());
		tv_all_price.setText("总计:￥"+mDataList.get(position).getReturn_goods_amount());
		tv_time.setText(mDataList.get(position).getCtime());
		tv_total.setText("总数："+mDataList.get(position).getReturn_goods_num());
		final int status=Integer.parseInt(mDataList.get(position).getReturn_status());
		switch (status){
			case 1:
				ll_state.setBackgroundColor(ContextCompat.getColor(mContext,R.color.appColor));
				if(mDataList.get(position).getReturn_type().equals("1")){
					tv_state.setText("同意退货");
				}else{
					tv_state.setText("同意换货");
				}

				break;
			case 2:
				ll_state.setBackgroundColor(ContextCompat.getColor(mContext,R.color.textLightGray));
				tv_state.setText("等待平台同意退货");
				break;
			case 3:
				ll_state.setBackgroundColor(ContextCompat.getColor(mContext,R.color.textLightGray));
				tv_state.setText("等待平台同意换货");
				break;
			case 4:
				ll_state.setBackgroundColor(ContextCompat.getColor(mContext,R.color.textLightGray));
				tv_state.setText("已完成");
				break;
			case 5:
				ll_state.setBackgroundColor(ContextCompat.getColor(mContext,R.color.textLightGray));
				tv_state.setText("审核未通过");
				break;
		}
		tv_state.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				if(null!=mListener)mListener.onLazyAdpListener(status,position,mDataList.get(position));
			}
		});
		ll_goods.removeAllViews();
		if(null!=mDataList.get(position).getOrder_goods()){
			int size = mDataList.get(position).getOrder_goods().size();
			for (int i = 0;i<size;i++){
				View view = mInflater.inflate(R.layout.item_frag_order_child,null);
				ImageView img = (ImageView) view.findViewById(R.id.goodsImg);
				TextView tv_name = (TextView) view.findViewById(R.id.tv_goodsName);
				TextView tv_price = (TextView) view.findViewById(R.id.tv_goodsPrice);
				TextView tv_count = (TextView) view.findViewById(R.id.tv_bugCount);
				tv_name.setText(mDataList.get(position).getOrder_goods().get(i).getGoods_name());
				tv_count.setText("x"+mDataList.get(position).getOrder_goods().get(i).getSale_num());
				tv_price.setText("￥"+mDataList.get(position).getOrder_goods().get(i).getSale_price());

				if(!TextUtils.isEmpty(mDataList.get(position).getOrder_goods().get(i).getGoods_image())) {
					Glide.with(mContext).load(mDataList.get(position).getOrder_goods().get(i).getGoods_image()).into(img);
				}

				view.setTag(mDataList.get(position).getOrder_goods().get(i).getContent_id());
				ll_goods.addView(view);
			}
		}
	} 
}
